package com.lins.small_tools;

import com.lins.store.controller.BaseController;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("utils")
public class GongZiUtils extends BaseController {

    @GetMapping({"index", "/"})
    public String utils(){
        return "<p style=\"color:green\">小工具</p>";
    }

    @GetMapping("gz")
    public String gz (@RequestParam Double gz) {
        double start = gz,step = 0.01,i = 150,s,r;int j=0;
        if(gz < 5000 || gz >= 100000) return "金额限制5千~10万";
        while (true){
            r = (double)Math.round(DoubleComputeUtil.sub(start, DoubleComputeUtil.sub(DoubleComputeUtil.mul(start, 0.03),i))*100)/100;
            s = (double)Math.round(DoubleComputeUtil.sub(DoubleComputeUtil.mul(start, 0.03),i)*100)/100;
            if (r == gz) return "根据你到手工资<div style=\"color:red\">"+r+"</div>元，反推"+j+"次计算得到您税前工资:<div style=\"color:blue\">"+start+"</div>元，纳税：<div style=\"color:green\">"+s+"</div>元";
            start = DoubleComputeUtil.add(start, step);
            j++;
            if (j == 1000000) return "强制停止：计算次数超过一百万次！";
        }
    }
}
